package com.iot08.api.service;

import com.alibaba.fastjson.JSONArray;
import com.iot08.common.entity.app.Questions;
import com.iot08.common.entity.app.QuestionsTitle;
import com.iot08.common.service.base.BaseService;
import com.iot08.common.utils.CollectionUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author weichao 1299101858@qq.com
 * @version 1.0
 * @date 4/29/22 2:40 PM
 */
@Slf4j
@Service
public class QuestionTitleService extends BaseService<QuestionsTitle> {
    /**
     * 根据条件查找 常见问题
     * @param query
     * @time: 4/29/22 6:06 PM
     * @author: Weichao
     * @version 1.0
     */
    public List getDataList (Query query) {
        List<Map<String, Object>> arr = new ArrayList<>();
        List<QuestionsTitle> questionsTitle = this.find(query);
        for (QuestionsTitle item : questionsTitle) {
            Map<String, Object> tempItem = new HashMap<>();
            tempItem.put("index", item.getIndex());
            tempItem.put("label", item.getLabel());
            tempItem.put("title", item.getTitle());
            tempItem.put("content", item.getContent());
            arr.add(tempItem);
        }
        //根据 index 降序排序
        CollectionUtil.sortDouble(arr, "index", 2);
        return arr;
    }
}
